<?php
//
defined('BY_JYA') or exit('error');
//cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
//$return=get_workerman2();
$return['ntime']=TIMESTAMP;
$basic = $this->plugin_setting('basic');
if($_RQ['op']=='main'){
	$auctionset=$this->plugin_setting('auction');
	$orderset=$this->plugin_setting('order');
	$category = pdo_getall('jy_jdpm_goods_group',array(),'','','paixu desc');
	$uid = $_SESSION['uid'];
	if($_RQ['fromuser']){
		$_SESSION['fromuser']=$_RQ['fromuser'];	
	}
	$nickname=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']),'nickname');
	$return['nickname']=$nickname;
    if ($uid) {
            // 用户订单状态显示
            $orderlist = array();
            $mywhere = array('mid' => $uid,'uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_jdpm');
            // 待付款
            $fukuai = $mywhere;
            $fukuai['status'] = 0;
			$ocount['fukuai'] = pdo_count('jy_weishop_order',$fukuai);
            // 待发货
            $fahuo = $mywhere;
            $fahuo['status'] = 1;
			$ocount['fukuai'] = pdo_count('jy_weishop_order',$fahuo);
            // 待收货
            $shouhuo = $mywhere;
            $shouhuo['status'] = 2;
			$ocount['fukuai'] = pdo_count('jy_weishop_order',$shouhuo);
            // 待评价
            $pingjia = $mywhere;
            $pingjia['status'] = 3;
			$ocount['fukuai'] = pdo_count('jy_weishop_order',$pingjia);
            // 用户订单状态显示】

            // 我的足迹【
			$pidstr = pdo_getall('jy_jdpm_member_footprint',array('mid' => $uid),'pidstr');
            // 字符串转换数组
			$pidarr = $pidstr?unserialize($pidstr):array(0);
            // 删除重复浏览的拍品
			
            $pidarr = array_flip(array_flip($pidarr));
            // 转换成字符串方便查询
			$params=array('uniacid'=>$_SESSION['uniacid'],'id'=>$pidarr,'hide' => 0);
			$orderby='field(id," . $pidstr . ")';
			$pindex = max(1, intval($_RQ['page']));
			$psize = 10;
			$total='';
			$footprint = pdo_getslice('jy_jdpm_auction',$params,array($pindex,$psize),$total,array('id','goodsid','nowprice'),'',$orderby);
       
            foreach ($footprint as $ftkey => $ftvl) {
                $footprint[$ftkey]['images'] = pdo_count('jy_jdpm_goods',array('id' => $ftvl['goodsid']),'images');
            }
            $return['footprint']=$footprint?$footprint:array();
			$totalpage=ceil($total/$psize);
			$totalpage=intval($totalpage);
			$return['totalpage'] =$totalpage;
			$return['params']['page'] =$pindex;
            // 我的足迹
        }
        /** be - kgdso */
        //商品分類
		$GoodsCategory =pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid']),array('id','pid', 'title', 'image'),'','paixu ASC');
		$return['GoodsCategory'] =$GoodsCategory;
        //拍卖专场
        // 不显示被屏蔽用户的拍品、专场、拍卖会
        $notinUid = array();
        if ($xUidarr = blackuser($uid)) {
            $notinUid = array('merchid <>' => $xUidarr);
        }
        // 开始的拍品、专场、拍卖会条件
        $stWhere = array(
			'uniacid'=>$_SESSION['uniacid'],
            'starttime <' => time(),
            'endtime >' => time()
        );
        // 专场、拍卖会内拍品必须大于0才显示
        $bcount = array('bcount >' => 0,'hide'=>0);

        //热卖专场
		$params=array_merge($stWhere, $notinUid, $bcount);
		$orderby='';
		$pindex = max(1, intval($_RQ['page']));
		$psize = 10;
		$total='';
		$spehot = pdo_getall('jy_jdpm_special_auction',$params,'','',$orderby);
        foreach ($spehot as $key => $val) {
			$goods = pdo_getslice('jy_jdpm_auction',array('id'=>$val['id']),array($pindex,$psize),$total,'','','paixu ASC');
			$spehot[$key]['goods'] = $goods;
			$spehot[$key]['num'] = pdo_getsum('jy_jdpm_auction',array('id'=>$val['id'],'starttime <'=>time(),'endtime >'=>time()),'bidcount');
        }
        $return['spehot']=$spehot?$spehot:array();
		$totalpage=ceil($total/$psize);
		$totalpage=intval($totalpage);
		$return['totalpage'] =$totalpage;
		$return['params']['page'] =$pindex;

        //预告专场
        $ForeshowWhere = array('uniacid'=>$_SESSION['uniacid'],'starttime >' => time());
		$params =array_merge($ForeshowWhere, $notinUid, $bcount);
		$orderby = 'starttime asc';
        $Foreshow = pdo_getall('jy_jdpm_special_auction',$params,'','',$orderby);
        foreach ($Foreshow AS $key => $val) {
            $goods = pdo_getslice('jy_jdpm_auction',array('id'=>$val['id'],'starttime <'=>time(),'endtime >'=>time()),array($pindex,$psize),$total,'','','msort ASC');
            foreach ($goods AS $k => $v) {
				$goodinfo = get_goodsinfo($v['goodsid']);
				$goodinfo['images'] = json_decode($goodinfo['images'],true);
				$goods[$k]['images'] = $goodinfo['images'];
				$goods[$k]['title'] = $goodinfo['title'];
			}
			$Foreshow[$key]['goods'] = $goods;
        }
        $return['Foreshow']=$Foreshow?$Foreshow:array();

        //最新拍卖
        $NewAuction = pdo_getslice('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'hide'=>0,'endstatus <'=>4,'ishot'=>1,'endtime >'=>time()),array($pindex,18),$total,'','','bidcount DESC , id DESC');
		foreach ($NewAuction AS $key => $val) {
            $goodinfo = get_goodsinfo($val['goodsid']);
			$goodinfo['images'] = json_decode($goodinfo['images'],true);
            $NewAuction[$key]['image'] = $goodinfo['image'];
			$NewAuction[$key]['title'] = $goodinfo['title'];
			$NewAuction[$key]['bidding']=$val['mid']>0 ?($val['nowprice']+($val['onset']/10)):$val['onset'];
			$NewAuction[$key]['clinch']=$val['mid']>0?$val['nowprice']:$val['onset'];
			$NewAuction[$key]['bzprice']=$val['mid']>0?(($val['nowprice'] +($val['onset']/10))>=($val['onset']*$orderset['onsetbi'])?($val['nowprice']+($val['onset']/10)):($val['nowprice']+($val['onset']/10))/2):$val['onset']/2;
			$NewAuction[$key]['ingname']=substr($val['mid'] ,0, 1) . '******' . substr($val['mid'] , -1);
			$NewAuction[$key]['status_ing'] = time() > $val['starttime'] ? (time() > $val['endtime'] ? 2 : 1) : 0;
			/** 是否拍中 **/
			$NewAuction[$key]['is_success'] = $val['mid'] == $_SESSION['uid'] ? 1 : 0;
			/** 竞拍人数 */
			$NewAuction[$key]['auctionNum'] = pdo_count('jy_jdpm_freezelog',array('pid' => $pid),'mid');
			$NewAuction[$key]['pname'] = cfc('tools')->substr($val['pname'],0,48);
        }
        $return['NewAuction']=$NewAuction?$NewAuction:array();
		
		//热卖拍卖
        $HotAuction = pdo_getslice('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'hide'=>0,'endstatus <'=>4,'ishot'=>1,'starttime <'=>time(),'endtime >'=>time()),array($pindex,18),$total,'','','id DESC');
		foreach ($HotAuction AS $key => $val) {
            $goodinfo = get_goodsinfo($val['goodsid']);
			$goodinfo['images'] = json_decode($goodinfo['images'],true);
            $HotAuction[$key]['image'] = $goodinfo['image'];
			$HotAuction[$key]['title'] = $goodinfo['title'];
			$HotAuction[$key]['bidding']=$val['mid']>0 ?($val['nowprice']+($val['onset']/10)):$val['onset'];
			$HotAuction[$key]['clinch']=$val['mid']>0?$val['nowprice']:$val['onset'];
			$HotAuction[$key]['bzprice']=$val['mid']>0?(($val['nowprice'] +($val['onset']/10))>=($val['onset']*$orderset['onsetbi'])?($val['nowprice']+($val['onset']/10)):($val['nowprice']+($val['onset']/10))/2):$val['onset']/2;
			$HotAuction[$key]['ingname']=substr($val['mid'] ,0, 1) . '******' . substr($val['mid'] , -1);
			$HotAuction[$key]['status_ing'] = time() > $val['starttime'] ? (time() > $val['endtime'] ? 2 : 1) : 0;
			/** 是否拍中 **/
			$HotAuction[$key]['is_success'] = $val['mid'] == $_SESSION['uid'] ? 1 : 0;
			/** 竞拍人数 */
			$HotAuction[$key]['auctionNum'] = pdo_count('jy_jdpm_freezelog',array('pid' => $pid),'mid');
			$NewAuction[$key]['pname'] = cfc('tools')->substr($val['pname'],0,48);
        }
        $return['HotAuction']=$HotAuction?$HotAuction:array();

        // 默认显示的拍品数量
        $limit = 12;
        // 显示的字段
        $field = array('pid','pname','nowprice','clcount','images','bidcount');
        // 频道板块
        $gCate = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],),'','','paixu desc');
        $channel = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'pid' =>0),'','','paixu asc');
        foreach ($channel as $ck => $cv) {
            // 获取需要查询的CID集合
            $gCidarr = getChildsId($gCate, $cv['id']);

            //获取分类下推荐分类
            $channel[$ck]['hotcate'] = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'pid' => $cv['id']),array('id','title'));
			
            array_unshift($gCidarr, $cv['cid']);//包含主分类
            $inCid = array('pid' => $gCidarr);
            // 组合条件
            $tWhere = array_merge($stWhere, $notinUid);
            $tCount = pdo_count('jy_jdpm_auction',$tWhere);
            $channel[$ck]['count'] = $tCount;
            if ($cv['modelno'] == 1) {
                // 效果一必须大于7个商品
                if ($tCount >= 7) {
                    $channel[$ck]['modelno'] = 1;
                    $limit = 7;
                } else {
                    $channel[$ck]['modelno'] = 0;
                }
            } elseif ($cv['modelno'] == 2) {
                // 效果一必须大于9个商品
                if ($tCount >= 9) {
                    $channel[$ck]['modelno'] = 2;
                    $limit = 9;
                } else {
                    $channel[$ck]['modelno'] = 0;
                }
            }
            // 按照结束时间倒叙获取该频道需要显示商品
            $channel[$ck]['list'] = pdo_getslice('jy_jdpm_auction',$tWhere,array($pindex,$limit),$total,'','','endtime desc');
        }
		$return['channel']=$channel?$channel:array();
        // 频道板块

        //最近成交拍品列表处理-----------------------------------------------start
        $edTime = endbid(0);
        $edWhere = array_merge($notinUid, $edTime,array('uniacid'=>$_SESSION['uniacid']));
        $edlist = pdo_getslice('jy_jdpm_auction',$edWhere,array($pindex,$limit),$total,'','','endtime desc');
        $return['edlist']=$edlist?$edlist:array();
        //最近成交拍品列表处理-----------------------------------------------end
        // 显示全部分类
		$return['cateshow']=1;
        // 计算小导航限时数量
        $sm_avg = 2;
        if ($auctionset['sort_time'] == 1) {
            $sm_avg += 1;
        }
        if ($auctionset['yikoujia'] == 1) {
            $sm_avg += 1;
        }
        if ($auctionset['jianlou'] == 1) {
            $sm_avg += 1;
        }
        if ($auctionset['special_page'] == 1) {
            $sm_avg += 1;
        }
        if ($auctionset['meeting_page'] == 1) {
            $sm_avg += 1;
        }
	$return['news'] = pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'','','id desc');
    $now = time();
    $return['sharedata'] =array(
			'title'=>$basic['title']?$basic['title']:'京东拍卖',
			'desc'=>$basic['desc']?$basic['desc']:'京东拍卖,最新商城模式,激活购物潜能！',
	);
	set_html('title','首页-'.$basic['title']?$basic['title']:'京东拍卖');
	$return['extradata']=array();
	$return['account']=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']));
	exi($return);
}	
?>